//
//  TZYDebrisListCell.m
//  Moment
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 片刻. All rights reserved.
//

#import "TZYDebrisListCell.h"

@interface TZYDebrisListCell ()

@property (nonatomic, retain)UIImageView *markImageView;
@property (nonatomic, retain)UIImageView *bigImageView;
@property (nonatomic, retain)UIImageView *headImageView;
@property (nonatomic, retain)UILabel *nameLabel;
@property (nonatomic, retain)UILabel *timeLabel;

@property (nonatomic, retain)UILabel *contentLabel;

@property (nonatomic, retain)UILabel *markLabel;
@property (nonatomic, retain)UILabel *markCountLabel;
@property (nonatomic, retain)UIImageView *commentImageView;
@property (nonatomic, retain)UILabel *commentLabel;
@property (nonatomic, retain)UIImageView *likeImageView;
@property (nonatomic, retain)UILabel *likeLabel;



@end


@implementation TZYDebrisListCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}


#pragma mark - 子视图
-(void)createSubView
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.headImageView = [[UIImageView alloc] init];
    self.headImageView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.headImageView];
    
    self.headImageView.layer.masksToBounds = YES;
    //设置半径
    self.headImageView.layer.cornerRadius = 25 / 2.0;
    //边框宽度
    self.headImageView.layer.borderWidth = 0;
    
    
    [self.headImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@10);
        make.top.mas_equalTo(@10);
        make.width.height.mas_equalTo(@25);
        
    }];
    
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameLabel];
    
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.headImageView.mas_right).offset(10);
        make.top.mas_equalTo(self.headImageView);
        make.width.mas_equalTo(@((SCREEN_WIDTH - 55) * (3.0 / 5)));
        make.height.mas_equalTo(self.headImageView);
        
    }];
    
    
    self.timeLabel = [[UILabel alloc] init];
    self.timeLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.timeLabel];
    
    [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.nameLabel.mas_right).offset(10);
        make.top.mas_equalTo(self.headImageView);
        make.right.mas_equalTo(@(-10));
        make.height.mas_equalTo(self.headImageView);
        
    }];
    
    

    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.contentLabel];
    
    
    self.markImageView = [[UIImageView alloc] init];
    //self.markImageView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.markImageView];
    
    self.markLabel = [[UILabel alloc] init];
    self.markLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.markLabel];
    
    self.markCountLabel = [[UILabel alloc] init];
    self.markCountLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.markCountLabel];
    
    self.commentImageView = [[UIImageView alloc] init];
    //self.commentImageView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.commentImageView];
    
    self.commentLabel = [[UILabel alloc] init];
    self.commentLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.commentLabel];
    
    self.likeImageView = [[UIImageView alloc] init];
    //self.likeImageView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.likeImageView];
    
    self.likeLabel = [[UILabel alloc] init];
    self.likeLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.likeLabel];
    
    
}


- (void)setDebrisDetail:(TZYDebrisDetail *)debrisDetail
{
    if (_debrisDetail != debrisDetail) {
        _debrisDetail = debrisDetail;
    }
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[self.debrisDetail.userinfo objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"iconfont-touxiang.png"]];
    
    self.nameLabel.text = [self.debrisDetail.userinfo objectForKey:@"uname"];
    self.nameLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForSmall]];
    self.timeLabel.text = self.debrisDetail.addtime_f;
    self.timeLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForSmall]];

    
    
    [self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@20);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(20);
        make.right.mas_equalTo(@(-20));
        make.height.mas_equalTo((SCREEN_HEIGHT / 4) / 2);
        
    }];
//
    self.contentLabel.text = self.debrisDetail.content;
    // 设置label的行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:self.contentLabel.text];;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:10];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.contentLabel.text.length)];
    self.contentLabel.attributedText = attributedString;
    self.contentLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForMiddle]];
    self.contentLabel.numberOfLines = 3;
    

    [self.markImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@20);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.width.height.mas_equalTo(@20);
        //make.height.mas_equalTo((SCREEN_HEIGHT / 4) / 2);
        
    }];
//
    self.markImageView.image = [UIImage imageNamed:@"iconfont-biaoqian.png"];

    
    
    
    
    
    [self.markLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.markImageView.mas_right).offset(0);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(self.markImageView);
        make.width.mas_equalTo(@(self.debrisDetail.markLabelWidth + 5));
        
    }];
    
    self.markLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForSmall]];
    NSString *markStr = [NSString stringWithFormat:@"·%@", [self.debrisDetail.tag_info objectForKey:@"tag"]];
    self.markLabel.text = markStr;
    self.markLabel.textColor = [UIColor colorWithRed:0.737 green:1.000 blue:0.689 alpha:1.000];
    
    
    
    
    [self.markCountLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.markLabel.mas_right).offset(2);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(self.markImageView);
        make.width.mas_equalTo(self.contentLabel).multipliedBy(0.15);
        
    }];
    
    
    self.markCountLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForSmall]];

    NSString *markCountStr = [NSString stringWithFormat:@"·%@", [self.debrisDetail.tag_info objectForKey:@"count"]];
    self.markCountLabel.text = markCountStr;
    
    
    [self.likeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(@(-20));
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@30);
        
    }];
    NSString *likeStr = [NSString stringWithFormat:@"%@", [self.debrisDetail.counterList objectForKey:@"like"]];
    self.likeLabel.text = likeStr;
    self.likeLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForSmall]];
    
    
    
    [self.likeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.likeLabel.mas_left).offset(-2);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.width.height.mas_equalTo(@20);
        
    }];
    self.likeImageView.image = [UIImage imageNamed:@"iconfont-xinxihuan00-2.png"];
    
    
    
    
    [self.commentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.likeImageView.mas_left).offset(-2);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@30);
        
    }];
    
    NSString *commentStr = [NSString stringWithFormat:@"%@", [self.debrisDetail.counterList objectForKey:@"comment"]];
    self.commentLabel.text = commentStr;
    self.commentLabel.font = [UIFont systemFontOfSize:[TZYFontSize getFontSizeForSmall]];
    
    
    [self.commentImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.commentLabel.mas_left).offset(-2);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(@20);
        make.width.mas_equalTo(@20);
        
    }];
    self.commentImageView.image = [UIImage imageNamed:@"iconfont-pinglun.png"];
    
    
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
